{template header}
<style type="text/css">
     td, th {
        min-width: 100px; max-width: 300px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis ;
         overflow: hidden; text-align: center;
}
   td:nth-child(1),
     th:nth-child(1) { max-width: 100px;  text-align: left;}
     td:nth-child(3),
     th:nth-child(3) { max-width: 80px; text-align: center; }
     td:nth-child(4),
     th:nth-child(4) { max-width: 30px; text-align: center; }
     td:nth-child(14),
     th:nth-child(14) { max-width: 20px; text-align: center; }
     td:nth-child(6),
     th:nth-child(6) { max-width: 60px; text-align: center; }
     td:nth-child(7),
     th:nth-child(7) { max-width: 60px; text-align: center; }
     


     .table-striped th,
     .table-striped td  { text-align: center;}
    
</style>
<div class="bs-docs-example" style="clear:both; padding-top: 30px;">
    <form method="post" action="">
    {$product['title']}
    <img width="200" src="$product['imageUrl']">
    <div class="control-group">
        <label class="control-label">顺序</label>
        <div class="controls">
            <input type="text" name="sort" value="0"/>
        </div>
    </div>
    <table class="table table-striped">
        <thead>
            <tr >
                <th>ID</th>
                <th>规格</th>
                <th>真实库存</th>
                <th>数量</th>
                <th>售价</th>
            </tr>
        </thead>
        <tbody>
            {loop $product['childGoods'] $k $v}
            <tr id="{$v['gid']}">
                <td><input type="text" readonly name="goods_ids[]" value="{$v['gid']}"></td>
                <td>{$v['attrPathName']}</td>
                <td>{$v['realStockNum']}</td>
                <td><input name="nums[]" id="num_{$k}" data-stock="{$v['realStockNum']}" value="{$v['realStockNum']}"></td>
                <td><input name="prices[]" data-k="{$k}" data-price="{$v['price']}" value="{$v['price']}"></td>
            </tr>
            {/loop}
        </tbody>
    </table>
    <input type="hidden" name="product_id" value="{$product['id']}">
    <button class="btn" type="submit">提交</button>
    </form>
</div>
<script>
(function(){
    $('input').blur(function(){
        if(isNaN($(this).val())){
            alert('请输入数字')
            return;
        }
        if($(this).data('stock')){
            if($(this).data('stock') < $(this).val()){
                alert('该规格货品可能存在超售情况，请注意')
            }
        }else if($(this).data('price')){
            if($(this).data('price') > $(this).val()){
                alert('该规格货品售价小于进货价，请注意')
            }
            if($(this).val()!=0 && $('#num_'+$(this).data('k')).val()==0){
                alert('库存为0价格不为0')
            }
        }
    })
}())
</script>
{template footer}
